#!/bin/bash
#

#判断主机是否存在密钥对
if [ -f /root/.ssh/id_rsa ];then
	rm -rf /root/.ssh/id_rsa*
fi

#生成新的密钥对
ssh-keygen -t rsa -f /root/.ssh/id_rsa -P "" &> /dev/null

#判断主机是否存在对方主机密钥对
if [ -f /root/.ssh/known_hosts ]; then
	> /root/.ssh/known_hosts
fi
#向远端主机拷贝公钥
for i in 11 12; do
/usr/bin/expect << eof
set timeout 5
spawn ssh-copy-id root@192.168.30.$i
expect "(yes/no)?"
send "yes\n"
expect "password:"
send "123\n"
expect eof
eof
done
